using IQIGame.Onigao.Framework;
using System;
using System.Collections.Generic;

namespace IQIGame.Onigao.Game
{
    public abstract class BaseConditionFunc : IReusableClass
    {
        public uint MaxStore => 50;
        public ConfigurableFSM fsm { get; protected set; }
        public LogicOperation prevLogicOperation { get; protected set; }

        protected List<object> paramList;
        protected CompareOperation compareOPeration;
        protected object targetValue;

        public void Init(ConfigurableFSM fsm, CFSMConditionPartCfg cfgPart)
        {
            this.fsm = fsm;
            this.paramList = cfgPart.paramValues;
            this.compareOPeration = cfgPart.compareOPeration;
            this.targetValue = cfgPart.targetValue;
            this.prevLogicOperation = cfgPart.prevLogicOperation;
            OnInit();
        }

        protected abstract void OnInit();

        public virtual bool Check()
        {
            return false;
        }

        protected bool Compare(int i)
        {
            switch (compareOPeration)
            {
                case CompareOperation.Equal:
                    return i == (int)targetValue;
                case CompareOperation.NotEqual:
                    return i != (int)targetValue;
                case CompareOperation.GreaterEqual:
                    return i >= (int)targetValue;
                case CompareOperation.LessEqual:
                    return i <= (int)targetValue;
                case CompareOperation.GreaterThan:
                    return i > (int)targetValue;
                case CompareOperation.LessThan:
                    return i < (int)targetValue;
                default:
                    return false;
            }
        }

        protected bool Compare(float i)
        {
            switch (compareOPeration)
            {
                case CompareOperation.Equal:
                    return i == (float)targetValue;
                case CompareOperation.NotEqual:
                    return i != (float)targetValue;
                case CompareOperation.GreaterEqual:
                    return i >= (float)targetValue;
                case CompareOperation.LessEqual:
                    return i <= (float)targetValue;
                case CompareOperation.GreaterThan:
                    return i > (float)targetValue;
                case CompareOperation.LessThan:
                    return i < (float)targetValue;
                default:
                    return false;
            }
        }

        protected bool Compare(bool i)
        {
            switch (compareOPeration)
            {
                case CompareOperation.Equal:
                    return i == (bool)targetValue;
                case CompareOperation.NotEqual:
                    return i != (bool)targetValue;
                default:
                    return false;
            }
        }

        protected bool Compare(string i)
        {
            switch (compareOPeration)
            {
                case CompareOperation.Equal:
                    return i == (string)targetValue;
                case CompareOperation.NotEqual:
                    return i != (string)targetValue;
                default:
                    return false;
            }
        }

        public virtual void OnReset()
        {
            fsm = null;
            prevLogicOperation = LogicOperation.None;
            paramList = null;
            compareOPeration = CompareOperation.None;
            targetValue = null;
        }
    }
}
